<?php 
// this file is to add items to inventory
// connect to mysql database
require("../storescripts/config.php");
//start session
session_start();


if (!isset($_SESSION["manager"])) {
    header("location: admin_login.php"); 
    exit();
}
?>
<?php 
// parse the data and add to inventory
if (isset($_POST['username'])) {
	
	//sanitize variables
    $username = mysql_real_escape_string($_POST['username']);
	$fname = mysql_real_escape_string($_POST['fname']);
	$lname = mysql_real_escape_string($_POST['lname']);
	$addr = mysql_real_escape_string($_POST['addr']);
	$email = mysql_real_escape_string($_POST['email']);
	
	//encrypt password
	$pass = md5($_POST['pass']);
	
	// check if the product has a match on database
	$sql = mysql_query("SELECT id FROM customers WHERE u_name='$username' LIMIT 1");
	
	// add this product into the database 
	$sql = mysql_query("INSERT INTO customers (f_name, l_name, address, u_name, password, email ) 
        VALUES('$fname','$lname','$addr','$username','$pass','$email')") or die (mysql_error());
     
	header("location: account_list.php"); 
    exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Add New User</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" />

<!-- start of javascript -->
<script type="text/javascript" language="javascript"> 
// validating forms before processing to a PHP script
function validateMyForm ( ) { 
    var isValid = true;
    if ( document.myForm.username.value == "" ) { 
	    alert ( "Please indicate username" ); 
	    isValid = false;
    } else if ( document.myForm.pass.value == "" ) { 
				alert ( "Please indicate password" ); 
				isValid = false;
	} else if ( document.myForm.pass2.value == "" ) { 
            alert ( "Please confirm password" ); 
            isValid = false;
    } else if ( document.myForm.pass.value != document.myForm.pass2.value ) { 
		            alert ( "Passwords don't match." ); 
		            isValid = false;
	} else if ( document.myForm.fname.value == "" ) { 
		            alert ( "Please indicate first name" ); 
		            isValid = false;
	} else if ( document.myForm.lname.value == "" ) { 
            alert ( "Please indicate last name" ); 
            isValid = false;
    } else if ( document.myForm.addr.value == "" ) { 
		     alert ( "Please indicate address" ); 
		     isValid = false;
	} else if ( document.myForm.email.value == "" ) { 
			 alert ( "Please indicate email" ); 
		 	 isValid = false;
	}
    return isValid;
}
</script>
<!--end of script -->

</head>

<body>
<!-- Main Shell -->
<div class="shell">
	
  <!-- Header -->
  <div id="header"><h1 id="logo"><a href="index.php">Luvo Fashion</a></h1>
	<div align="right" style="padding-right:5px; padding-top:40px;">
		<a style="color:#ccc;" href="account_list.php">Back</a>&nbsp; |
		<a style="color:#ccc;" href="logout.php">Logout</a>
	</div>
  </div>
  <!-- End Header -->

  <!-- Main -->
  <div id="main">
    <div align="center" style="background:#ebebeb; width:800px; margin-left:80px; margin-top:15px; padding-top:5px; padding-bottom:5px;">
    <a name="accountForm" id="accountForm"></a>
    <h3>&darr; Add New User Form &darr;</h3>
    <br />
    <br />
    <form action="account_form.php" enctype="multipart/form-data" name="myForm" id="myform" method="post">
    <table width="90%" border="0" cellspacing="5" cellpadding="10">
      	<table border="0">
		 	<tr>
			<td>Username:</td><td>
		 		<input type="text" name="username" maxlength="60" size="40">
		 	</td></tr>
		 	<tr><td>Password:</td><td>
		 		<input type="password" name="pass" maxlength="10" size="40">
		 	</td></tr>
		 	<tr><td>Confirm Password:</td><td>
		 		<input type="password" name="pass2" maxlength="10" size="40">
		 	</td></tr>
		 	<tr><td>First Name:</td><td>
		 		<input type="text" name="fname" maxlength="255" size="40">
		 	</td></tr>
		 	<tr><td>Last Name:</td><td>
		 		<input type="text" name="lname" maxlength="255" size="40">
		 	</td></tr>
		 	<tr><td>Address:</td><td>
		 		<input type="textarea" name="addr" maxlength="255" size="40">
		 	</td></tr>
		 	<tr><td>Email:</td><td>
		 		<input type="text" name="email" maxlength="255"size="40">
		 	</td></tr>
		 	<tr>
			<td>&nbsp;</td>
			<th><input type="submit" name="submit" value="Create User"></th>
			</tr> 
		</table>
    </table>
    </form>
    </div>
  </div>
<!-- End Main -->
  
<!-- Footer -->
   <div style="padding-top:5px;" id="footer">
    <p class="left">Add User</p>
    <p class="right"> &copy; 2010 Luvo Fashion.</p>
    </div>
<!-- End Footer -->

</div>
<!-- End Shell -->

</body>
</html>